package com.shixj.demo.exchanger;

import java.util.ArrayList;
import java.util.concurrent.Exchanger;

/**
 * Created by shixj on 2017/9/26.
 */
public class Even implements Runnable {
    final Exchanger<ArrayList<Integer>> exchanger;
    private final ArrayList<Integer> even = new ArrayList<Integer>(5);
    public Even(Exchanger<ArrayList<Integer>> exchanger) {
        this.exchanger = exchanger;
    }

    @Override
    public void run() {
        for(int i=2;i<11;i=i+2){
            even.add(i);
        }
        System.out.println("偶数列（原数列）："+even);
        try{
           System.out.println("偶数列（现数列）："+exchanger.exchange(even));
        }catch (InterruptedException e){
            e.printStackTrace();
        }

    }
}
